package towerDefense;

/**
 * Class to give each player necessary tools
 * 
 * @author Guillermo Mendez-Kestler
 *
 */
public class Player {
	/**
	 * Amount of CREDITS the PLAYER has
	 */
	private int CREDITS;

	/**
	 * Creates a PLAYER with 100 starting CREDITS
	 */
	public Player() {
		CREDITS = 100;
	}

	/**
	 * Creates a PLAYER with the amount of CREDITS specified
	 * @param credits
	 */
	public Player(int credits) {
		CREDITS = credits;
	}

	/**
	 * Returns the number of CREDITS available in the bank. 
	 * 
	 * @return The number of CREDITS available in the bank. 
	 */
	public int getCredits(){
		return CREDITS;
	}

	/**
	 * Purchases a Tower, each tower has a specified cost.  
	 * 
	 * @param type TOWER TYPE to be purchased.
	 * @return If the purchase was successful or not. 
	 */
	public boolean buyTower(int type) {
		int cost;
		switch(type){
		case 0: cost=Tower_Bullet.INITIAL_BUILD_COST; break;
		case 1: cost=Tower_Fire.INITIAL_BUILD_COST; break;
		default:cost=0; break;
		}
		if (CREDITS<cost)
			return false;
		else{ 
			switch(type){
			case 0: new Tower_Bullet(); break;
			case 1: new Tower_Fire(); break;
			default: break;
			}
			CREDITS-=cost;
			return true;
		}
	}
	
	/**
	 * Purchases a Tower at the specified location. Each tower has a specified cost.
	 * The Tower is centered at the specified location.   
	 * 
	 * @param type TOWER TYPE to be purchased.
	 * @param x_coord The center X coordinate of the Tower 
	 * @param y_coord The center Y coordinate of the Tower
	 * @param size Size of the tower. 
	 * @return If the purchase was successful or not.
	 */
	public boolean buyTower(int type, double x_coord, double y_coord, double size) {
		int cost;
		switch(type){
		case 0: cost=Tower_Bullet.INITIAL_BUILD_COST; break;
		case 1: cost=Tower_Fire.INITIAL_BUILD_COST; break;
		default:cost=0; break;
		}
		if (CREDITS<cost)
			return false;
		else{  
			switch(type){
			case 0: new Tower_Bullet(x_coord, y_coord); break;
			case 1: new Tower_Fire(x_coord, y_coord); break;
			default: break;
			}
			CREDITS-=cost;
			return true;
		}
	}

	/**
	 * Upgrades an object for the cost provided. 
	 * 
	 * @param tower TOWER to upgrade
	 * @return If the purchase was successful or not. 
	 */
	public boolean upgradeTower(T_Tower tower){
		int cost = tower.costToUpgrade();
		if (CREDITS<cost)
			return false;
		else {
			if (!tower.upgradeTower()) 
				return false;
			CREDITS-=cost;
			return true;
		}
	}

}
